package com.tarena.lbs.message.web.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.message.web.mapper.MessageMapper;
import com.tarena.lbs.pojo.message.po.MessagePO;
import com.tarena.lbs.pojo.message.query.MessageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class MessageRepository {
    @Autowired
    private MessageMapper messageMapper;

    public void saveMessage(MessagePO messagePO) {
        messageMapper.insert(messagePO);
    }

    public List<MessagePO> selectAll() {
        List<MessagePO> pos = messageMapper.selectList(null);
        return pos;
    }

    public List<MessagePO> getUserMessages(MessageQuery messageQuery) {
        QueryWrapper<MessagePO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("msg_type",1);
        queryWrapper.eq("user_id", messageQuery.getUserId());
        return messageMapper.selectList(queryWrapper);
    }
}
